package com.ease.util {

   import flash.events.Event;

   /**
    * This class represents an event indicating some change in the type of events raised or
    * received by a given object, e.g. a new type being added to the set of event types that
    * an even dispatcher raises.
    */
   public class EventTypeUpdateEvent extends ObjectEvent {
      /**
       * Event type id for notifying the addition of an event type to a dispatcher.
       */
      public static const TYPE_ADDED_TO_DISPATCHER:String = "typeAddedToDispatcher";

      /**
       * Event type id for notifying the removal of an event type from a dispatcher.
       */
      public static const TYPE_REMOVED_FROM_DISPATCHER:String = "typeRemovedFromDispatcher";

      /**
       * Initializes an instance of this class.
       *
       * @param type
       *    The id for the event.
       *
       * @param object
       *    Value for the object property.
       *
       * @param eventTypeAddedOrRemoved
       *    The event type that is being added to or removed from the set of event types
       *    dispatched by the given object.
       *
       * @param bubbles
       *    Whether the event should bubble or not.
       */
      public function EventTypeUpdateEvent( type:String, object:Object = null,
                                            eventTypeAddedOrRemoved:String = null,
                                            bubbles:Boolean = true ) {
         super( type, object, bubbles );
         _eventTypeAddedOrRemoved = eventTypeAddedOrRemoved;
      }

      //---------------------------------------------------------------------------
      // Class Methods

      /**
       * A convenience factory method to create an instance of this class that represents
       * the addition of a new event type to a dispatcher object.
       */
      public static function
         newDispatchTypeAddition( object:Object, eventTypeAdded:String ):EventTypeUpdateEvent {
         return new EventTypeUpdateEvent( TYPE_ADDED_TO_DISPATCHER, object, eventTypeAdded );
      }

      /**
       * A convenience factory method to create an instance of this class that represents
       * the removal of an event type from a dispatcher object.
       */
      public static function
         newDispatchTypeRemoval( object:Object, eventTypeRemoved:String ):EventTypeUpdateEvent {
         return new EventTypeUpdateEvent( TYPE_REMOVED_FROM_DISPATCHER, object,
            eventTypeRemoved );
      }

      //---------------------------------------------------------------------------
      // Instance Properties

      //-------------------------------------------------------
      // treatsViewsAsMediators

      private var _eventTypeAddedOrRemoved:String;

      /**
       * The event type that is being added or removed from amongst the type of events that
       * the given object raises or consumes.
       */
      public function get eventTypeAddedOrRemoved():String {
         return _eventTypeAddedOrRemoved;
      }

      //---------------------------------------------------------------------------
      // Overridden Methods

      /**
       * Creates a clone of this event. All custom events should override this method.
       *
       * @return
       *  A clone of this event.
       */
      public override function clone():Event {
         return new EventTypeUpdateEvent( type, super.object, _eventTypeAddedOrRemoved );
      }
   }

}